package controller;

import dao.DatailsDao;
import entity.Datails;

import entity.Shiyan;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import service.DatailsService;
import service.LinService;


import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/Qbb")
public class DatailsCon {
    @Resource(name = "datailsService")
    private DatailsService datailsService;

    @Resource(name = "datailsDao")
    private  DatailsDao datailsDao;


    @Resource(name="linService")
    private LinService linService;

    @RequestMapping("/QqueryByOrder")
    @ResponseBody
    public List<Datails> QqueryByOrder(String order1){
        List<Datails> list=datailsService.QqueryByOrder(order1);

        return list;
    }

    @RequestMapping("/Qquer")
    @ResponseBody
    public Map<String,Object> Qqueryxianshi(String supplierid,int pageSize,int pageNumber, String firstDate1,String secondDate1){
        Datails datails=new Datails();
        int id = -1;
        if(supplierid!=null && supplierid !=""){
            id = Integer.parseInt(supplierid);
        }
        datails.setSupplierid(id);

        Map<String,Object> mapResult=new HashMap<String,Object>();
        Map<String,Object> map=new HashMap<String,Object>();

        map.put("supplierid",supplierid);
        map.put("secondDate1",secondDate1);
        map.put("firstDate1",firstDate1) ;
        map.put("offset",(pageNumber-1) * pageSize) ;
        map.put("pageSize",pageSize);
        List<Datails> datails1=datailsService.QqueryGHSMC(map);

        mapResult.put("total",datailsDao.QgetCount(map));
        mapResult.put("rows",datails1);
        return mapResult;
    }


    @RequestMapping("/Qduoshao")
    @ResponseBody
    public List<Datails> Qduoshao(String supplierid){
        Datails datails = new Datails();

        int id2=-1;


        if(supplierid!=null && supplierid !=""){
            id2 = Integer.parseInt(supplierid);
        }

        datails.setSupplierid(id2);
        List<Datails> list=datailsService.Qqueryfenlei(id2);

        return list;
    }



    @RequestMapping("/Qminxi")
    @ResponseBody
    public Map<String,Object> Qminxi(String name,String typeid,String supplierid,int pageSize,int pageNumber, String firstDate1,String secondDate1){
        Datails datails=new Datails();
        datails.setName(name);
        int id = -1;
        if(typeid!=null && typeid !=""){
            id = Integer.parseInt(typeid);
        }
        int id2=-1;
        if(supplierid!=null && supplierid!=""){
            id2=Integer.parseInt(supplierid);
        }
        datails.setSupplierid(id2);
        datails.setTypeid(id);
        Map<String,Object> mapResult=new HashMap<String,Object>();
        Map<String,Object> map=new HashMap<String,Object>();

        map.put("supplierid",supplierid);
        map.put("name",name);
        map.put("typeid",typeid);
        map.put("secondDate1",secondDate1);
        map.put("firstDate1",firstDate1) ;
        map.put("offset",(pageNumber-1) * pageSize) ;
        map.put("pageSize",pageSize);
        List<Datails> datails1=datailsService.QqueryBy(map);

        mapResult.put("total",datailsDao.QgetCount(map));
        mapResult.put("rows",datails1);
        return mapResult;
    }

    @RequestMapping("/Qchuhuo")
    @ResponseBody
    public Map<String,Object> Qchuhuo(String supplierid,int pageSize,int pageNumber, String firstDate1,String secondDate1){
        Datails datails=new Datails();

        Map<String,Object> mapResult=new HashMap<String,Object>();
        Map<String,Object> map=new HashMap<String,Object>();
        int id = -1;
        datails.setSupplierid(id);
        if(supplierid!=null && supplierid !=""){
            id = Integer.parseInt(supplierid);
            map.put("supplierid",id);

        }else{
            map.put("supplierid",supplierid);

        }

        map.put("secondDate1",secondDate1);
        map.put("firstDate1",firstDate1) ;
        map.put("offset",(pageNumber-1) * pageSize) ;
        map.put("pageSize",pageSize);
        List<Datails> datails1=datailsService.Qchuhuo(map);

        mapResult.put("total", datailsDao.Qchuhuofenye(map));
        mapResult.put("rows",datails1);
        return mapResult;
    }

    @RequestMapping("/qquery")
    @ResponseBody
    public Map<String,Object> query(String supplierid,int pageSize,int pageNumber, String firstDate1,String secondDate1){

        int i = linService.qing();


        Map<String,Object> mapResult=new HashMap<String,Object>();
        Map<String,Object> map=new HashMap<String,Object>();

        map.put("supplierid",supplierid);
        map.put("secondDate1",secondDate1);
        map.put("firstDate1",firstDate1) ;
        map.put("offset",(pageNumber-1) * pageSize) ;
        map.put("pageSize",pageSize);
        List<Datails> datails1=datailsService.query(map);

        mapResult.put("total",datailsDao.count(map));
        mapResult.put("rows",datails1);
        return mapResult;
    }


    @RequestMapping("/tui")
    @ResponseBody
    public Map<String,Object> tt(String supplierid,String warehouseid,String lei,String name, int pageSize,int pageNumber){

        Map<String,Object> mapResult=new HashMap<String,Object>();
        Map<String,Object> map=new HashMap<String,Object>();

        map.put("supplierid",supplierid);
        map.put("warehouseid",warehouseid);
        map.put("companyid",lei) ;
        map.put("name",name) ;
        map.put("offset",(pageNumber-1) * pageSize) ;
        map.put("pageSize",pageSize);
        List<Datails> datails1=datailsService.list3(map);

        mapResult.put("total",datailsService.list31(map).size());
        mapResult.put("rows",datails1);
        return mapResult;
    }

   /* 跳转到货品出货统计*/
   @RequestMapping("/Qhuopinchuhuotongji")
   public String tiaozhuan(Model model) {
       return "WEB-INF/jsp/tongjibaobiao/huopinchuhuotongji";
   }


   @RequestMapping("/Qchtongji")
   @ResponseBody
    public Map<String,Object> Qchtongji(String typeid,String name,String typeid1,String name1,int pageSize,int pageNumber, String firstDate,String secondDate,String firstDate1,String secondDate1){


       Datails datails=new Datails();


       Map<String,Object> mapResult=new HashMap<String,Object>();
       Map<String,Object> map=new HashMap<String,Object>();

       int id=-1;
       if(typeid!=null && typeid !=""){
           id = Integer.parseInt(typeid);
          map.put("typeid",id);

       }else{
            map.put("typeid",typeid);

       }
       int id1=-1;
       if(typeid1!=null && typeid1 !=""){
           id1 = Integer.parseInt(typeid1);
           map.put("typeid1",id1);
           System.out.println(id1);
       }else{
           map.put("typeid1",typeid1);
           System.out.println(typeid1);

       }
       datails.setTypeid(id);

       datails.setTypeid(id1);

       datails.setName(name);

       datails.setName(name1);

       map.put("name",name);

       map.put("name1",name1);


       map.put("secondDate",secondDate);
       map.put("firstDate",firstDate) ;

       map.put("secondDate1",secondDate1);
       map.put("firstDate1",firstDate1) ;








       map.put("offset",(pageNumber-1) * pageSize) ;
       map.put("pageSize",pageSize);

       List<Datails> datails1=datailsService.Qchuhuotongji(map);

       mapResult.put("total",datailsDao.Qsss(map));
       mapResult.put("rows",datails1);
       return mapResult;
    }




   /* 按供货商查询*/
   @RequestMapping("/Qangonghuoshang")
   @ResponseBody
   public List<Datails> Qchtongji(String name){

       Datails datails=new Datails();

       Map<String,Object> map=new HashMap<String,Object>();
       datails.setName(name);
       map.put("name",name);

       List<Datails> datails1=datailsService.Qangongshangtongji(map);


       return datails1;

   }
   /*按客户统计*/
   @RequestMapping("/Qankehutongji")
   @ResponseBody
   public List<Datails> Qankehutongji(String supplierid){

       Datails datails=new Datails();

       Map<String,Object> map=new HashMap<String,Object>();


       int id2=-1;
       if(supplierid!=null && supplierid !=""){
           id2 = Integer.parseInt(supplierid);
           map.put("supplierid",id2);

       }else{
           map.put("supplierid",supplierid);

       }

       datails.setSupplierid(id2);
       map.put("supplierid",supplierid);


       List<Datails> datails1=datailsService.Qankehutongji(map);


       return datails1;

   }





   /*按供货商统计查询详细*/
   @RequestMapping("/Qangonghuoshangxx")
   @ResponseBody
   public List<Datails> Qangonghuoshangxx(String typeid){

       Datails datails=new Datails();

       Map<String,Object> map=new HashMap<String,Object>();

       int id=-1;
       if(typeid!=null && typeid !=""){
           id = Integer.parseInt(typeid);
           map.put("typeid",id);

       }else{
           map.put("typeid",typeid);

       }
       datails.setTypeid(id);

       List<Datails> datails1=datailsService.Qangongshangtongjixx(map);


       return datails1;

   }



    /*出货分类分类统计表*/
    @RequestMapping("/Qhpchtongjibiao")
    @ResponseBody
    public List<Datails> Qhpchtongjibiao(String typeid,String name, String firstDate,String secondDate){


        Datails datails=new Datails();
        Map<String,Object> mapResult=new HashMap<String,Object>();
        Map<String,Object> map=new HashMap<String,Object>();

        int id=-1;
        if(typeid!=null && typeid !=""){
            id = Integer.parseInt(typeid);
            map.put("typeid",id);

        }else{
            map.put("typeid",typeid);

        }
        datails.setTypeid(id);

        datails.setName(name);
        map.put("name",name);
        map.put("secondDate",secondDate);
        map.put("firstDate",firstDate) ;
        List<Datails> datails1=datailsService.Qhpchtongjibiao(map);
        return datails1;
    }

    /*出货排行*/
    @RequestMapping("/Qpaihang")
    @ResponseBody
    public List<Datails> Qpaihang(String typeid,String name, String firstDate,String secondDate){


        Datails datails=new Datails();
        Map<String,Object> mapResult=new HashMap<String,Object>();
        Map<String,Object> map=new HashMap<String,Object>();

        int id=-1;
        if(typeid!=null && typeid !=""){
            id = Integer.parseInt(typeid);
            map.put("typeid",id);

        }else{
            map.put("typeid",typeid);

        }
        datails.setTypeid(id);

        datails.setName(name);
        map.put("name",name);
        map.put("secondDate",secondDate);

        map.put("firstDate",firstDate) ;


        List<Datails> datails1=datailsService.Qchuhuopaihang(map);



        return datails1;
    }



    /* 跳蛛到库存成本统计*/
    @RequestMapping("/Qkkccccbbttjj")
    public String Qkkccccbbttjj(Model model) {
        return "WEB-INF/jsp/tongjibaobiao/kucunchengbentongji";
    }



    /*仓库变动*/
    @RequestMapping("/QBiantong")
    public String QBiantong(Model model) {
        return "WEB-INF/jsp/tongjibaobiao/kucundiaoboutongji";
    }

    @RequestMapping("/Qhguszelnk")
    @ResponseBody
    public List<Datails> Qshi(){
        List<Datails> datails1=datailsService.Qkucunbiantong();
        List<Datails> datails2=datailsService.Qkucunbiantongjichu();

        System.out.println("1------"+datails1.size());
        System.out.println("2------"+datails2.size());



        for(int i = 0;i<datails1.size();i++){

            datails2.add(datails1.get(i));


//            datails2.get(datails2.size()+i+1).setNames(datails1.get(i).getNames());
//            datails2.get(datails2.size()+i+1).setCompanyid(datails1.get(i).getCompanyid());
//            datails2.get(datails2.size()+i+1).setDates(datails1.get(i).getDates());
//            datails2.get(datails2.size()+i+1).setTypeid(datails1.get(i).getTypeid());
        }
        return datails2;
    }

}
